/**
 * @Description: test
 * @Author: Hu Outstanding
 * @Date: 2022/2/19 9:46
 */
package com.aaa.three.service.impl;

import com.aaa.three.mapper.AdminQueryDeptMapper;
import com.aaa.three.pojo.query.AdminInfoDept;
import com.aaa.three.pojo.query.DeptDocState;
import com.aaa.three.pojo.query.DeptState;
import com.aaa.three.result.AjaxResult;
import com.aaa.three.service.AdminQueryDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminQueryDeptServiceImpl implements AdminQueryDeptService {

    @Autowired
    private AdminQueryDeptMapper adminQueryDept;


    @Override
    public AjaxResult queryAllDept() {
        List<AdminInfoDept> queryAllDepts = adminQueryDept.queryAllDept();
        return AjaxResult.success(queryAllDepts);
    }

    @Override
    public AjaxResult getDept(int id) {
        AdminInfoDept getDeptInfo = adminQueryDept.getDept(id);
        return AjaxResult.success(getDeptInfo);
    }

    @Override
    public AjaxResult deleteDept(int id) {
         int i = adminQueryDept.deleteDept(id);
        if (i > 0 ){
            return AjaxResult.success();
        }
        return AjaxResult.fail("删除失败");
    }

    @Override
    public AjaxResult addDept(AdminInfoDept adminInfoDept) {

        String name = adminInfoDept.getDname();

        int q = adminQueryDept.countName(name);

        if (q == 0 ){
            int i = adminQueryDept.addDept(adminInfoDept);
            if (i > 0 ){
                return AjaxResult.success();
            }
            return AjaxResult.fail("添加失败");
        }
        return AjaxResult.fail("部门已经存在");
    }

    @Override
    public AjaxResult queryDeptState() {

        List<DeptState> queryDeptState = adminQueryDept.queryDeptState();

        return AjaxResult.success(queryDeptState);
    }

    @Override
    public AjaxResult queryDocState() {
        List<DeptDocState> queryDocState = adminQueryDept.queryDocState();

        return AjaxResult.success(queryDocState);
    }

    @Override
    public AjaxResult updateDept(AdminInfoDept adminInfoDept) {

        int i = adminQueryDept.updateDept(adminInfoDept);
        if (i > 0){
            return AjaxResult.success();
        }
        return AjaxResult.fail("部门修改失败");
    }
}
